/**
 * 
 */
package com.zdy.im.tio.command.handler;

import com.zdy.im.common.exception.ImException;
import com.zdy.im.core.ICommand;
import com.zdy.im.tio.command.AbstractCommandHandler;

import com.zdy.im.tio.command.Command;
import org.springframework.stereotype.Component;
import org.tio.core.ChannelContext;
import org.tio.core.intf.Packet;


/**
 * 版本: [1.0]
 * 功能说明: 获取用户信息消息命令
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 */
@Component
//@ApiDoc(module = "WebSocket 项目文档",group = "SOCKET-GROUP")
public class UserReqHandler extends AbstractCommandHandler {
	/**
	 * 非持久化用户信息接口
	 */
//	private IUserInfo nonPersistentUserInfo;
//	/**
//	 * 持久化用户信息接口
//	 */
//	private IUserInfo persistentUserInfo;
//
//	public UserReqHandler(){
//		persistentUserInfo = new PersistentUserInfo();
//		nonPersistentUserInfo = new NonPersistentUserInfo();
//	}
	@Override
	public ICommand command() {
		return Command.COMMAND_GET_USER_REQ;
	}

	@Override
	public Packet handler(Packet packet, ChannelContext channelContext) throws ImException {
//		UserReqBody userReqBody = JsonKit.toBean(packet.getBody(),UserReqBody.class);
//		String userId = userReqBody.getUserId();
//		if(StringUtils.isEmpty(userId)) {
//			return ProtocolManager.Converter.respPacket(new RespBody(Command.COMMAND_GET_USER_RESP, ImStatus.C10004), imChannelContext);
//		}
//		//(0:所有在线用户,1:所有离线用户,2:所有用户[在线+离线]);
//		Integer type = userReqBody.getType() == null ? UserStatusType.ALL.getNumber() : userReqBody.getType();
//		if(Objects.isNull(UserStatusType.valueOf(type))){
//			return ProtocolManager.Converter.respPacket(new RespBody(Command.COMMAND_GET_USER_RESP, ImStatus.C10004), imChannelContext);
//		}
//		RespBody resPacket = new RespBody(Command.COMMAND_GET_USER_RESP);
//		ImServerConfig imServerConfig = ImConfig.Global.get();
//		//是否开启持久化;
//		boolean isStore = ImServerConfig.ON.equals(imServerConfig.getIsStore());
//		if(isStore){
//			resPacket.setData(persistentUserInfo.getUserInfo(userReqBody, imChannelContext));
//		}else {
//			resPacket.setData(nonPersistentUserInfo.getUserInfo(userReqBody, imChannelContext));
//		}
//		//在线用户
//		if(UserStatusType.ONLINE.getNumber() == userReqBody.getType()){
//			resPacket.setCode(ImStatus.C10005.getCode()).setMsg(ImStatus.C10005.getMsg());
//			//离线用户;
//		}else if(UserStatusType.OFFLINE.getNumber() == userReqBody.getType()){
//			resPacket.setCode(ImStatus.C10006.getCode()).setMsg(ImStatus.C10006.getMsg());
//			//在线+离线用户;
//		}else if(UserStatusType.ALL.getNumber() == userReqBody.getType()){
//			resPacket.setCode(ImStatus.C10003.getCode()).setMsg(ImStatus.C10003.getMsg());
//		}
//		return ProtocolManager.Converter.respPacket(resPacket, imChannelContext);
		return null;
	}

//	public IUserInfo getNonPersistentUserInfo() {
//		return nonPersistentUserInfo;
//	}
//
//	public void setNonPersistentUserInfo(IUserInfo nonPersistentUserInfo) {
//		this.nonPersistentUserInfo = nonPersistentUserInfo;
//	}
//
//	public IUserInfo getPersistentUserInfo() {
//		return persistentUserInfo;
//	}
//
//	public void setPersistentUserInfo(IUserInfo persistentUserInfo) {
//		this.persistentUserInfo = persistentUserInfo;
//	}

}
